package org.one.stone.soup.grfxML.plugin.control;


import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.plugin.SimplePlugin;
import org.one.stone.soup.grfxML.plugin.grfxMLCaster;
import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.LockException;

public class Mover extends SimplePlugin {


	public static final int ARG_POSITION = 0;

	public static final int ARG_MOVEUP = 1;

	public static final int ARG_MOVEDOWN = 2;

	public static final int ARG_MOVELEFT = 3;

	public static final int ARG_MOVERIGHT = 4;



	org.one.stone.soup.grfxML.DataPoint position = new org.one.stone.soup.grfxML.DataPoint();

	org.one.stone.soup.grfxML.DataState moveUp = new org.one.stone.soup.grfxML.DataState();

	org.one.stone.soup.grfxML.DataState moveDown = new org.one.stone.soup.grfxML.DataState();

	org.one.stone.soup.grfxML.DataState moveLeft = new org.one.stone.soup.grfxML.DataState();

	org.one.stone.soup.grfxML.DataState moveRight = new org.one.stone.soup.grfxML.DataState();

	int cap = 10;
	int dx =0;
	int dy =0;
/**
 * Mover constructor comment.
 */
public Mover (GrfxMLEngine engine){
	super(engine);
}
/**
 * initialize method comment.
 */
public void initialize() {}
/**
 * process method comment.
 */
public void process()
{
 try{
	if(moveDown.getValue()==true)
	{
		if(dy<0)
			dy=0;
		if(dy<cap)
			dy++;
		position.setValueY( position.getValueY()+dy,this );
	}
	if(moveUp.getValue()==true)
	{
		if(dy>0)
			dy=0;
		if(dy>-cap)
			dy--;
		position.setValueY( position.getValueY()+dy,this );
	}
	if(moveRight.getValue()==true)
	{
		if(dx<0)
			dx=0;
		if(dx<cap)
			dx++;
		position.setValueX( position.getValueX()+dx,this );
	}
	if(moveLeft.getValue()==true)
	{
		if(dx>0)
			dx=0;
		if(dx>-cap)
			dx--;
		position.setValueX( position.getValueX()+dx,this );
	}
 }catch(LockException le){}
}
/**
 * register method comment.
 */
public void register(DataLinker store)
{

	position = grfxMLCaster.cast(position,getArg(position,ARG_POSITION,store));

	moveUp = grfxMLCaster.cast(moveUp,getArg(moveUp,ARG_MOVEUP,store));

	moveDown = grfxMLCaster.cast(moveDown,getArg(moveDown,ARG_MOVEDOWN,store));

	moveLeft = grfxMLCaster.cast(moveLeft,getArg(moveLeft,ARG_MOVELEFT,store));

	moveRight = grfxMLCaster.cast(moveRight,getArg(moveRight,ARG_MOVERIGHT,store));

}
/**
 * replace method comment.
 */
public void replace(Field oldObj, Field newObj)
{

	position = grfxMLCaster.replace(position,oldObj,newObj);

	moveUp = grfxMLCaster.replace(moveUp,oldObj,newObj);

	moveDown = grfxMLCaster.replace(moveDown,oldObj,newObj);

	moveLeft = grfxMLCaster.replace(moveLeft,oldObj,newObj);

	moveRight = grfxMLCaster.replace(moveRight,oldObj,newObj);

}
/**
 * stop method comment.
 */
public void stop() {}
}
